/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 *
 * $Id: IOData.hpp,v 1.3 2009-05-13 07:18:17 amaula Exp $
 *
 * \file
 * \brief MaCI - IO Data parser header
 * \author Matthieu Myrsky <matthieu.myrsky@tkk.fi>
 */
#ifndef _MACI_INTERFACE_IODATA_HPP_
#define _MACI_INTERFACE_IODATA_HPP_

#include "IOTypes.hpp"
#include "timestamp.hpp"
#include "MaCIData.hpp"
#include <stdio.h>
#include <vector>

namespace gim {
  namespace binbag{class CBinBag;}
}


namespace MaCI {
  namespace IO {

    /** IO Data Decoder/Encoder.
     * This class implements the io data decoding and encoding to/from binbag
     *
     */
    class CIOData : public CMaCIData
    {
    public:
       /** Constructor of CIOData
       *
       */
      CIOData(void);

      /** Destructor of CIOData
       *
       */
      ~CIOData(void);


      /** Copy constructor for IOData. 
       *
       * The copy constructor duplicates the input object to maximum
       * depth (All containers are duplicated too). After a copy is
       * constructed, no dependencies to original Data element exist.
       *
       * @param[in] aIOData Reference to CIOData container to copy.
       */
      CIOData(const CIOData &aIOData);

      /** Assignment operator for IOData.
       *
       * The assignment operator duplicates the input object to
       * maximum depth (All containers are duplicated too). After a
       * copy is constructed, no dependencies to original Data element
       * exist.
       *
       * @param[in] aIOData Reference to CIOData container to copy.
       */
      CIOData &operator=(const CIOData &aIOData);

      ///////////////////////////////////////////////////
      // Derived from 'CMaCIData', see description there.
      bool DecodeFrom(gim::binbag::CBinBag *aBinBag = NULL);
      void Reset();
      void Print(const int level) const;
      ///////////////////////////////////////////////////


      // Setter commands
      /** Set Timestamp element.
       * 
       * \see Common::TTimestamp
       *
       * @param[in] aStamp      Timestamp element to set.
       * @return                'true' if no such element previously
       *                        exists, and a valid binbag::CBinBag backend exists.
       */
      bool SetTimestamp(const Common::TTimestamp &aStamp);

      bool SetDigitalPinState(const TDigitalPinState &aState);

      bool SetDigitalBlockState(const TDigitalBlockState &aState);

      bool SetAnalogVoltage(const TAnalogVoltage &aAnalogVoltage);

      bool SetDigitalBlockMask(const TDigitalBlockMask &mask);

      /** Set Command element.
       *
       * Command elements must be accompanied by related dataelement
       * when required by commandtype. See the command enumerations
       * for a note about required datatype. (For example, 'SetDigitalPin'
       * command required a 'DigitalPin' datatype after the command.
       * 
       * \see TCommand
       *
       * @param[in] aCmd        Command element to set.
       * @return                'true' if no such element previously
       *                        exists, and a valid binbag::CBinBag backend exists.
       */
      bool SetCommand(const TCommand &aCmd);
      // Getter commands

      /** Get constantpointer to TCommand element (if such exists).
       *
       * \see TCommand
       * 
       * @return                constant Pointer to command
       *                        element if such element exists
       *                        in the container. If the element 
       *                        doesn't exist, NULL is returned.
       */
      const TCommand *GetCommand(void) const;
      /** Get pointer to Common::TTimestamp element (if such exists).
       *
       * \see Common::TTimestamp
       * 
       * @return                Constant pointer to timestamp
       *                        element if such element exists
       *                        in the container. If the element 
       *                        doesn't exist, NULL is returned.
       */
      const Common::TTimestamp *GetTimestamp(void) const;
      
      
      const TDigitalPinState *GetDigitalPinState(void) const;
      
      const TDigitalBlockState *GetDigitalBlockState(void) const;
      
      const TAnalogVoltage *GetAnalogVoltage(void) const;


      const TDigitalBlockMask *GetDigitalBlockMask(void) const;
    private:
      bool iValid;
      
      const Common::TTimestamp *iTimestampPtr; ///< Pointer to Timestamp
      const TCommand *iCommandPtr; ///< Pointer to command if any.
      const TDigitalPinState *iPinState;
      const TDigitalBlockState *iBlockState;
      const TAnalogVoltage *iAnalogVoltage;
      const TDigitalBlockMask *iBlockMask;
    };
  }
}

#endif ///<_MACI_INTERFACE_IODATA_HPP_
